﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HIWSystem.Common;
using HIWSystem.Models;
using HIWSystem.Helpers;
using System.Windows.Media;
using System.IO;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;

namespace HIWSystem.ViewModel
{
    public class PlanOutputInfoEntryViewModel :ViewModelBase
    {
        #region 属性
        private string templateName= "ProductionPlanOutputImportTemplate";
        /// <summary>
        /// 模板名称
        /// </summary>
        public string TemplateName
        {
            get { return templateName; }
            set { templateName = value; this.RaisePropertyChanged(() => TemplateName); }
        }

        private ObservableCollection<ProductionPlanEntity> records;
        /// <summary>
        /// 添加的记录
        /// </summary>
        public ObservableCollection<ProductionPlanEntity> Records
        {
            get { return records; }
            set { records = value; this.RaisePropertyChanged(() => Records); }
        }
        private Brush processMsgForeground=Brushes.Black;
        /// <summary>
        /// 过程信息的字体颜色
        /// </summary>
        public Brush ProcessMsgForeground
        {
            get { return processMsgForeground; }
            set { processMsgForeground = value; this.RaisePropertyChanged(() => ProcessMsgForeground); }
        }
        private string processMsg="";
        /// <summary>
        /// 过程信息
        /// </summary>
        public string ProcessMsg
        {
            get { return processMsg; }
            set { processMsg = value; this.RaisePropertyChanged(() => ProcessMsg); }
        }
        private Visibility isVisibleLoading=Visibility.Collapsed;
        /// <summary>
        /// 是否显示加载动画
        /// </summary>
        public Visibility IsVisibleLoading
        {
            get { return isVisibleLoading; }
            set { isVisibleLoading = value; this.RaisePropertyChanged(() => IsVisibleLoading); }
        }
        private Visibility isVisibilityProgressBarPanel=Visibility.Collapsed;
        /// <summary>
        /// 是否显示进度条面板
        /// </summary>
        public Visibility IsVisibilityProgressBarPanel
        {
            get { return isVisibilityProgressBarPanel; }
            set { isVisibilityProgressBarPanel = value; this.RaisePropertyChanged(() => IsVisibilityProgressBarPanel); }
        }
        private double progressBarValue;
        /// <summary>
        /// 进度条当前值
        /// </summary>
        public double ProgressBarValue
        {
            get { return progressBarValue; }
            set { progressBarValue = value; this.RaisePropertyChanged(() => ProgressBarValue); }
        }
        private double progressBarMaximum;
        /// <summary>
        /// 进度条最大值
        /// </summary>
        public double ProgressBarMaximum
        {
            get { return progressBarMaximum; }
            set { progressBarMaximum = value; this.RaisePropertyChanged(() => ProgressBarMaximum); }
        }
        private double progressBarMinimum;
        /// <summary>
        /// 进度条最小值
        /// </summary>
        public double ProgressBarMinimum
        {
            get { return progressBarMinimum; }
            set { progressBarMinimum = value; this.RaisePropertyChanged(() => ProgressBarMinimum); }
        }

        #endregion

        #region 命令

        private RelayCommand importCmd;

        public RelayCommand ImportCmd
        {
            get {
                importCmd = importCmd ?? new RelayCommand(BatchImportAsync);
                return importCmd; }
            set { importCmd = value; }
        }
        private RelayCommand downloadCm;

        public RelayCommand DownloadCmd
        {
            get {
                downloadCm = downloadCm ?? new RelayCommand(DownloadTemplate);
                return downloadCm; }
            set { downloadCm = value; }
        }

        #endregion

        #region 方法
        //批量导入
        private async void BatchImportAsync()
        {
            string batchDataFilePath = string.Empty; //批量数据文件路径
            StringBuilder errorMsg = new StringBuilder();//异常信息
            bool result = false;//验证结果
            await Task.Run(() =>
            {
                try
                {
                    AddProcessInfo("******************************开始处理**************************************", Brushes.Blue);
                    IsVisibleLoading = Visibility.Visible; //显示加载动画
                    AddProcessInfo("正在选择批量报告文件...", Brushes.Black);
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    openFileDialog.Filter = "Excel文件（*.xls;*.xlsx）|*.xls;*.xlsx"; //"(*.xls, *.xlsx) | *.xls; *.xlsx ";
                    openFileDialog.Title = "选择批量报告文件";
                    if (openFileDialog.ShowDialog() == true)
                    {
                        batchDataFilePath = openFileDialog.FileName;
                        AddProcessInfo(string.Format("已选择批量报告文件，文件路径【{0}】", batchDataFilePath), Brushes.Green);
                        var excelHeaderAndEntityPropertyMapping = new Dictionary<string, string>();
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.WO), "工单");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.PN), "机种");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.Station), "生产工序");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.PlanOutput), "计划产量");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.WeekDay), "星期");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.Week), "周别");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.Year), "年份");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.Shift), "班别");
                        excelHeaderAndEntityPropertyMapping.Add(nameof(ProductionPlanEntity.Actor), "录入人");
                        AddProcessInfo("正在验证导入的模板标题和数据上限...", Brushes.Black);
                        result = BusinessProcess.VerifyExcelTemplateHeaderAndDataUpperLimit(excelHeaderAndEntityPropertyMapping, batchDataFilePath, out errorMsg);
                        if (result)
                        {
                            AddProcessInfo("导入报告的模板标题和数据上限没有问题", Brushes.Green);
                            AddProcessInfo("正在将Excel数据添加到实体类型中...", Brushes.Black);
                            var excelEntities = BusinessProcess.ExcelToEntityList<ProductionPlanEntity>(excelHeaderAndEntityPropertyMapping, batchDataFilePath, out errorMsg, 2);
                            //errorMsg为空表示表中的数据符合规范
                            if (errorMsg.ToString() == "" && excelEntities.Count >0)
                            {
                                AddProcessInfo("验证导入的数据在系统中是否存在", Brushes.Black);
                                //将生产计划产量基础表填充到实体集合中
                                var sqlEntities = BusinessProcess.SqlTableToEntityConvert<ProductionPlanEntity>("select * from ProductionPlan");
                                AddProcessInfo("正在循环检测Excel每行数据在系统中是否存在...", Brushes.Black);
                                int repeatCount = 0;//重复数据的数量
                                for (int i = 0; i < excelEntities.Count; i++)
                                {
                                    //判断excel实体类型和sql实体类型是否一样，一样表示已经保存过。避免重复保存数据
                                    if (sqlEntities.Count(s => s.WO == excelEntities[i].WO && s.PN == excelEntities[i].PN && s.PlanOutput == excelEntities[i].PlanOutput && s.WeekDay == excelEntities[i].WeekDay && s.Week == excelEntities[i].Week && s.Year == excelEntities[i].Year) > 0)
                                    {
                                        //i+3 这里加3第一下标从0开始第二是为了和excel的实际行数对应，excel中数据内容是从第三行开始
                                        errorMsg.AppendLine("Excel中第" + (i +3) + "行的数据在系统中已经存在,请检查数据填写是否有误?");
                                        repeatCount += 1;
                                    }
                                }
                                AddProcessInfo(string.Format("检测完毕  总共【{0}】条 满足【{1}】条 不满足【{2}】条", excelEntities.Count, excelEntities.Count - repeatCount, repeatCount), Brushes.Green);
                                //errorMsg为空表示没有重复的数据
                                if (errorMsg.ToString() == "")
                                {
                                    AddProcessInfo("检查完成！开始保存数据到数据库中...", Brushes.Black);
                                    //将List实体准换成Datatable便于后面的批量存储做准备
                                    DataTable dtEntities = BusinessProcess.ListToDatatableConvert(excelEntities, "ProductionPlan");
                                    result = SqlHelper.BatchInsertBySqlBulkCopy(dtEntities, out errorMsg);
                                    if (result)
                                    {
                                        AddProcessInfo("批量保存数据成功!", Brushes.Green);
                                        AddProcessInfo("开始将数据显示在前台...", Brushes.Black);
                                        Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                                        {
                                            Records = new ObservableCollection<ProductionPlanEntity>();
                                            foreach (var e in excelEntities)
                                            {

                                                Records.Add(e);
                                            }
                                        }));
                                       
                                        AddProcessInfo("******************************处理完成**************************************", Brushes.Blue);
                                    }
                                    else
                                    {
                                        AddProcessInfo(errorMsg.ToString(), Brushes.Red);
                                    }

                                }
                                else
                                {
                                    AddProcessInfo(errorMsg.ToString(), Brushes.Red);
                                }
                            }
                            else
                            {
                                AddProcessInfo(errorMsg.ToString(), Brushes.Red);
                            }
                        }
                        else
                        {
                            AddProcessInfo(errorMsg.ToString(), Brushes.Red);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(string.Format("批量导入生产计划产量数据时出现错误【{0}】", ex.Message), ex);
                    MessageBox.Show("批量导入失败！", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
                    AddProcessInfo(string.Format("批量导入生产计划产量数据时出现错误【{0}】", ex.Message), Brushes.Red);
                }
                finally
                {
                    Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        this.IsVisibilityProgressBarPanel = Visibility.Collapsed;
                        this.IsVisibleLoading = Visibility.Collapsed;
                    }));
                }
            });
        }
        /// <summary>
        /// 下载模板
        /// </summary>
        private void DownloadTemplate()
        {
            string templateFilePath = string.Empty;//模板文件路径
            string templateSavePath = string.Empty;//模板保存路径
            if ((TemplateName??"")=="")
            {
                MessageBox.Show("模板名称不能为空!","软件温馨提示",MessageBoxButton.OK,MessageBoxImage.Warning);
                return;
            }
            AddProcessInfo("正在检索目标模板文件", Brushes.Black);
            //检索路径下名称是TemplateName的.xls和.xlsx扩展名文件
            var dirInfo = new DirectoryInfo(Global.AppConfigs.BatchImportTemplatePath);
            var templateSourcefileInfo = dirInfo.GetFiles().Where(f=>f.Name==TemplateName+".xls"||f.Name==TemplateName+".xlsx").FirstOrDefault();
            if (templateSourcefileInfo == null)
            {
                MessageBox.Show("没有搜索到模板,请检查路径和模板名称是否正确.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            AddProcessInfo(string.Format("已经检查到目标模板文件,路径【{0}】",templateSourcefileInfo.FullName),Brushes.Black);
            //打开文件夹对话框选择保存模板的文件夹路径
            var dialog = new CommonOpenFileDialog();
            dialog.IsFolderPicker = true;
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            AddProcessInfo("请选择保存模板文件的路径",Brushes.Black);
            CommonFileDialogResult result = dialog.ShowDialog();
            if (result==CommonFileDialogResult.Ok)
            {
                try
                {
                    AddProcessInfo("正在下载模板....",Brushes.Black);
                    templateSavePath = Path.Combine(dialog.FileName, templateSourcefileInfo.Name);
                    FileInfo templateTargetFileInfo = new FileInfo(templateSavePath);
                    //判断目标路径文件是否存在，不存在则创建
                    if (!templateTargetFileInfo.Exists)
                        templateTargetFileInfo.Create().Close();
                    //拷贝模板到目标文件夹
                    File.Copy(templateSourcefileInfo.FullName, templateTargetFileInfo.FullName, true);
                    MessageBox.Show("模板下载成功！请打开模板填写数据","软件温馨提示",MessageBoxButton.OK,MessageBoxImage.Information);
                    AddProcessInfo("下载成功!",Brushes.Green);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("下载失败！", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    AddProcessInfo(string.Format("下载过程中发生错误，错误信息【{0}】!",ex.Message), Brushes.Red);
                }
            }
        }
        /// <summary>
        /// 添加过程信息
        /// </summary>
        /// <param name="msg">信息</param>
        /// <param name="color">字体颜色</param>
        private void AddProcessInfo(string msg, Brush color)
        {
            Application.Current.Dispatcher.BeginInvoke((Action)(() =>
            {
                ProcessMsgForeground = color;
                ProcessMsg = msg;
            }));
        }
        /// <summary>
        /// 页面加载事件
        /// </summary>
        //private void LoadedPage()
        //{
        //    FillWOToCombobox();
        //    FillStationToCombobox();
        //    FillWeekDayToCombobox();
        //    FillWeekToCombobox();
        //    FillYearToCombobox();
        //    FillShiftToCombobox();
        //}

        //private void Add()
        //{
        //    ProductionPlanEntity entity = new ProductionPlanEntity();
        //    string retMsg = string.Empty;//数据库返回的状态码和状态信息
        //    string[] arrayMsg = new string[2]; //截取返回的状态码和状态信息
        //    try
        //    {
        //        if (!VerifyControlContent()) return;
        //        entity.WO = this.WO;
        //        entity.Shift = this.Shift ?? "白班";
        //        entity.Station = this.Station;
        //        entity.PlanOutput = this.PlanOutput;
        //        entity.WeekDay = this.WeekDayValue;
        //        entity.Week = this.Week;
        //        entity.Year = this.Year??DateTime.Now.Year.ToString();
        //        entity.Actor= LogInInfo.User;
        //        retMsg = BusinessProcess.AddProductionPlanOutput(entity);
        //        arrayMsg = retMsg.Split('|');
        //        if (arrayMsg[0] == "OK")
        //        {
        //            //首次添加要初始化Log集合
        //            if (Records == null)
        //                Records = new ObservableCollection<ProductionPlanEntity>();
        //            Records.Add(new ProductionPlanEntity
        //            {
        //                WO=this.WO,
        //                Station=this.Station,
        //                PlanOutput=this.PlanOutput,
        //                Shift=entity.Shift,
        //                WeekDay=this.WeekDayValue,
        //                Week=this.Week,
        //                Year=entity.Year,
        //                Actor=entity.Actor,
        //                CreateAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        //            });
        //            //根据时间进行降序排序，便于将最近一条记录显示再最上面。
        //            var a = Records.OrderByDescending(x => Convert.ToDateTime(x.CreateAt)).ToList();
        //            Records = new ObservableCollection<ProductionPlanEntity>();
        //            for (int i = 0; i < a.Count; i++)
        //            {
        //                Records.Add(new ProductionPlanEntity
        //                {
        //                    WO = a[i].WO,
        //                    Station = a[i].Station ?? "",
        //                    PlanOutput = a[i].PlanOutput,
        //                    Shift=a[i].Shift,
        //                    WeekDay=a[i].WeekDay,
        //                    Week=a[i].Week,
        //                    Year=a[i].Year,
        //                    Actor=a[i].Actor,
        //                    CreateAt = a[i].CreateAt ?? "",
        //                }) ;
        //            }
        //        }
        //        else
        //        {
        //            MessageBox.Show(arrayMsg[1], "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //       MessageBox.Show(string.Format("执行插入的时候发生异常【{0}】",ex.Message),"软件温馨提示!",MessageBoxButton.OK,MessageBoxImage.Error);
        //        LogHelper.WriteLog(ex.Message, ex);
        //    }

        //}
        ////验证控件内容
        //private bool VerifyControlContent()
        //{
        //    if ((WO??"")=="")
        //    {
        //       MessageBox.Show("工单信息不能为空","软件温馨提示!",MessageBoxButton.OK,MessageBoxImage.Error);
        //       return false;
        //    }
        //    if ((Station ?? "") == "")
        //    {
        //        MessageBox.Show("工序信息不能为空", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
        //        return false;
        //    }
        //    int result = 0;
        //    if (!int.TryParse(PlanOutput.ToString(), out result))
        //    {
        //        MessageBox.Show("产量信息不是数字", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
        //        return false;
        //    }
        //    if ((WeekDayValue ?? "") == "")
        //    {
        //        MessageBox.Show("星期信息不能为空", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
        //        return false;
        //    }
        //    if ((Week ?? "") == "")
        //    {
        //        MessageBox.Show("周别信息不能为空", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
        //        return false;
        //    }
        //    return true;
        //}
        ///// <summary>
        ///// 填充星期信息
        ///// </summary>
        //private void FillWeekDayToCombobox()
        //{
        //    WeekDays = new ObservableCollection<ProductionPlanEntity>();
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "一" ,WeekDayValue="1"});
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "二", WeekDayValue = "2" });
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "三", WeekDayValue = "3" });
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "四", WeekDayValue = "4" });
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "五", WeekDayValue = "5" });
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "六", WeekDayValue = "6" });
        //    WeekDays.Add(new ProductionPlanEntity { WeekDay = "日", WeekDayValue = "7" });
        //}

        ///// <summary>
        ///// 填充工序到下拉列表框
        ///// </summary>
        //private void FillStationToCombobox()
        //{
        //    List<string> lstStations = new List<string>();
        //    lstStations = Global.AppConfigs.ProductionPlanInfo.Station.Split('|').ToList<string>();
        //    Stations = new ObservableCollection<StationsEntity>();
        //    for (int i = 0; i < lstStations.Count; i++)
        //    {
        //        Stations.Add(new StationsEntity { Station = lstStations[i] });
        //    }
        //}
        // //填充工单信息到下拉列表框
        //private void FillWOToCombobox()
        //{
        //    DataTable dtWos = new DataTable();
        //    dtWos = BusinessProcess.GetWOInfo("*");
        //    WOs = new ObservableCollection<WOEntity>();
        //    for (int i = 0; i < dtWos.Rows.Count; i++)
        //    {
        //        WOs.Add(new WOEntity { WO = dtWos.Rows[i]["WO"].ToString() });
        //    }
        //}
        ////填充班别信息到下拉列表框
        //private void FillShiftToCombobox()
        //{
        //    List<string> lstShifts = new List<string>();
        //    lstShifts = Global.AppConfigs.ProductionPlanInfo.Shift.Split('|').ToList<string>();
        //    Shifts = new ObservableCollection<ProductionPlanEntity>();
        //    for (int i = 0; i < lstShifts.Count; i++)
        //    {
        //        Shifts.Add(new ProductionPlanEntity { Shift = lstShifts[i] });
        //    }
        //}
        ////填充周别信息到下拉列表框
        //private void FillWeekToCombobox()
        //{
        //    List<string> lstWeeks = new List<string>();
        //    lstWeeks = Global.AppConfigs.ProductionPlanInfo.Week.Split('|').ToList<string>();
        //    Weeks = new ObservableCollection<ProductionPlanEntity>();
        //    for (int i = 0; i < lstWeeks.Count; i++)
        //    {
        //        Weeks.Add(new ProductionPlanEntity { Week = lstWeeks[i] });
        //    }
        //}
        ////填充年份信息到下拉列表框
        //private void FillYearToCombobox()
        //{
        //    List<string> lstYears = new List<string>();
        //    lstYears = Global.AppConfigs.ProductionPlanInfo.Year.Split('|').ToList<string>();
        //    Years = new ObservableCollection<ProductionPlanEntity>();
        //    for (int i = 0; i < lstYears.Count; i++)
        //    {
        //        Years.Add(new ProductionPlanEntity { Year = lstYears[i] });
        //    }
        //}
        ///// <summary>
        ///// 筛选工单下拉列表框中的数据
        ///// </summary>
        //private void FilterWO()
        //{

        //    IsOpenComboWODropDown = true;
        //    //当是第一次过滤的时候备份原始数据
        //    //这样是为了当不输入搜索条件时添加原始数据到列表中
        //    //当输入搜索条件时生成过滤集合绑定当下拉列表中
        //    if (isFirstFilterWO)
        //    {
        //        backupWOs = new ObservableCollection<WOEntity>();
        //        backupWOs = WOs;
        //        isFirstFilterWO = false;
        //    }
        //    if (!string.IsNullOrEmpty(SearchWOText) && WOs != null)
        //    {
        //        IEnumerable<WOEntity> WOEntities = WOs.Where(s => s.WO.ToUpper().Contains(SearchWOText.ToUpper()));
        //        WOs = new ObservableCollection<WOEntity>();
        //        foreach (var w in WOEntities)
        //        {
        //            WOs.Add(w);
        //        }
        //    }
        //    else
        //    {
        //        WOs = backupWOs;
        //    }

        //}
        ///// <summary>
        ///// 筛选工序下拉列表框中的数据
        ///// </summary>
        //private void FilterStation()
        //{
        //    IsOpenComboStationDropDown = true;
        //    //当是第一次过滤的时候备份原始数据
        //    //这样是为了当不输入搜索条件时添加原始数据到列表中
        //    //当输入搜索条件时生成过滤集合绑定当下拉列表中
        //    if (isFirstFilterStation)
        //    {
        //        backupStations = new ObservableCollection<StationsEntity>();
        //        backupStations = Stations;
        //        isFirstFilterStation = false;
        //    }
        //    if (!string.IsNullOrEmpty(SearchStationText) && Stations != null)
        //    {
        //        IEnumerable<StationsEntity> StationEntities = Stations.Where(s => s.Station.ToUpper().Contains(SearchStationText.ToUpper()));
        //        Stations = new ObservableCollection<StationsEntity>();
        //        foreach (var s in StationEntities)
        //        {
        //            Stations.Add(s);
        //        }
        //    }
        //    else
        //    {
        //        Stations = backupStations;
        //    }

        //}
        ///// <summary>
        ///// 筛选周别下拉列表框中的数据
        ///// </summary>
        //private void FilterWeek()
        //{
        //    IsOpenComboWeekDropDown = true;
        //    //当是第一次过滤的时候备份原始数据
        //    //这样是为了当不输入搜索条件时添加原始数据到列表中
        //    //当输入搜索条件时生成过滤集合绑定当下拉列表中
        //    if (isFirstFilterWeek)
        //    {
        //        backupWeeks = new ObservableCollection<ProductionPlanEntity>();
        //        backupWeeks = Weeks;
        //        isFirstFilterWeek = false;
        //    }
        //    if (!string.IsNullOrEmpty(SearchWeekText) && Weeks != null)
        //    {
        //        IEnumerable<ProductionPlanEntity> WeekEntities = Weeks.Where(w => w.Week.ToUpper().Contains(SearchWeekText.ToUpper()));
        //        Weeks = new ObservableCollection<ProductionPlanEntity>();
        //        foreach (var w in WeekEntities)
        //        {
        //            Weeks.Add(w);
        //        }
        //    }
        //    else
        //    {
        //        Weeks = backupWeeks;
        //    }

        //}
        ///// <summary>
        ///// 筛选年份下拉列表框中的数据
        ///// </summary>
        //private void FilterYear()
        //{
        //    IsOpenComboYearDropDown = true;
        //    //当是第一次过滤的时候备份原始数据
        //    //这样是为了当不输入搜索条件时添加原始数据到列表中
        //    //当输入搜索条件时生成过滤集合绑定当下拉列表中
        //    if (isFirstFilterYear)
        //    {
        //        backupYears = new ObservableCollection<ProductionPlanEntity>();
        //        backupYears = Years;
        //        isFirstFilterYear = false;
        //    }
        //    if (!string.IsNullOrEmpty(SearchYearText) && Years != null)
        //    {
        //        IEnumerable<ProductionPlanEntity> YearEntities = Years.Where(y=> y.Year.ToUpper().Contains(SearchYearText.ToUpper()));
        //        Years = new ObservableCollection<ProductionPlanEntity>();
        //        foreach (var y in YearEntities)
        //        {
        //            Years.Add(y);
        //        }
        //    }
        //    else
        //    {
        //        Years = backupYears;
        //    }
        //}

        //private void FilterWeekDay()
        //{
        //    IsOpenComboWeekDayDropDown = true;
        //    //当是第一次过滤的时候备份原始数据
        //    //这样是为了当不输入搜索条件时添加原始数据到列表中
        //    //当输入搜索条件时生成过滤集合绑定当下拉列表中
        //    if (isFirstFilterWeekDay)
        //    {
        //        backupWeekDays = new ObservableCollection<ProductionPlanEntity>();
        //        backupWeekDays = WeekDays;
        //        isFirstFilterWeekDay = false;
        //    }
        //    if (!string.IsNullOrEmpty(SearchWeekDayText) && WeekDays != null)
        //    {
        //        IEnumerable<ProductionPlanEntity> WeekDayEntities = WeekDays.Where(wd => wd.WeekDay.ToUpper().Contains(SearchWeekDayText.ToUpper()));
        //        WeekDays = new ObservableCollection<ProductionPlanEntity>();
        //        foreach (var w in WeekDayEntities)
        //        {
        //            WeekDays.Add(w);
        //        }
        //    }
        //    else
        //    {
        //        WeekDays = backupWeekDays;
        //    }
        //}

        #endregion
    }
}
